@extends('backend.layouts.app')

@section('title', $title = $playerBetFlow->id ? '游戏编辑' : '添加游戏' )

@section('breadcrumb')
    <a href="">系统设置</a>
    <a href="">网站管理</a>
    <a href="">{{$title}}</a>
@endsection

@section('content')
    <div class="layui-main">

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>{{ $title }}</legend>
        </fieldset>

        <form class="layui-form layui-form-pane" method="POST"
              action="{{ $playerBetFlow->id ? route('player_bet_flow.update', $playerBetFlow->id) : route('player_bet_flow.store') }}">
            {{ csrf_field() }}
            <input type="hidden" name="_method" class="mini-hidden" value="{{ $playerBetFlow->id ? 'PATCH' : 'POST' }}">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">网站</label>
                    <div class="layui-input-inline">
                        <select name="site_username" lay-verify="" lay-search="" lay-filter="siteSelect">
                            <option value="">请选择网站</option>
                            @foreach($sites as $site)
                                <option value={{$site->username}} @if($site->username==$playerBetFlow->site_username) selected='' @endif >{{$site->site_name}}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux">site_username</div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">平台</label>
                    <div class="layui-input-inline">
                        <select name="main_game_plat_code" id="plats" lay-verify="" lay-search="" lay-filter="platSelect">
                            <option value="">请选择平台</option>
                            @if($playerBetFlow->id)
                                <option value={{$playerBetFlow->main_game_plat_code}} selected=''>{{$playerBetFlow->main_game_plat_code}}</option>
                            @endif
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux">site_username</div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">玩家</label>
                    <div class="layui-input-inline">
                        <select name="username" id="players" lay-verify="" lay-search="">
                            <option value="">请选择玩家</option>
                            @if($playerBetFlow->id)
                                <option value={{$playerBetFlow->username}} selected=''>{{$playerBetFlow->username}}</option>
                            @endif
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux">username</div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">游戏编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="game_code" lay-verify="" placeholder="请输入游戏编号"
                               autocomplete="off" class="layui-input" value="{{old('game_code',$playerBetFlow->game_code)}}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">参考游戏列表(game_code)</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">平台单号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="game_flow_code" lay-verify="" placeholder="请输入平台单号"
                               autocomplete="off" class="layui-input" value="{{old('game_flow_code',$playerBetFlow->game_flow_code)}}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">自定义单号(game_flow_code)</div>
                </div>

            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" title="投注金额">投注金额</label>
                    <div class="layui-input-inline">
                        <input type="text" name="bet_amount" lay-verify="" placeholder="请输入投注金额"
                               autocomplete="off" class="layui-input"
                               value="{{old('bet_amount',$playerBetFlow->bet_amount)}}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">大于等于0得正数(bet_amount)</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" title="有效投注">有效投注</label>
                    <div class="layui-input-inline">
                        <input type="text" name="available_bet_amount" lay-verify=""
                               placeholder="请输入有效投注"
                               autocomplete="off" class="layui-input"
                               value="{{old('available_bet_amount',$playerBetFlow->available_bet_amount)}}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">大于等于0得正数(available_bet_amount)</div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" title="公司派彩">公司派彩</label>
                    <div class="layui-input-inline">
                        <input type="text" name="company_payout_amount" lay-verify=""
                               placeholder="请输入公司派彩"
                               autocomplete="off" class="layui-input"
                               value="{{old('company_payout_amount',$playerBetFlow->company_payout_amount)}}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">数字(company_payout_amount)</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" title="公司输赢">公司输赢</label>
                    <div class="layui-input-inline">
                        <input type="text" name="company_win_amount" lay-verify=""
                               placeholder="请输入公司输赢"
                               autocomplete="off" class="layui-input"
                               value="{{old('company_win_amount',$playerBetFlow->company_win_amount)}}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">数字(company_win_amount)</div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" title="平台类型">平台类型</label>
                    <div class="layui-input-inline">
                        <input type="text" name="plat_type" lay-verify=""
                               placeholder="请输入平台类型"
                               autocomplete="off" class="layui-input"
                               value="{{old('plat_type',$playerBetFlow->plat_type)}}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">大厅类型(plat_type)</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" title="大厅类型">大厅类型</label>
                    <div class="layui-input-inline">
                        <input type="text" name="lobby_type" lay-verify=""
                               placeholder="请输入大厅类型"
                               autocomplete="off" class="layui-input"
                               value="{{old('lobby_type',$playerBetFlow->lobby_type)}}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">(lobby_type)</div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">投注时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="bet_time" name="bet_time"
                               placeholder="yyyy-MM-dd HH:mm:ss"
                               value="{{old('bet_time',$playerBetFlow->bet_time)}}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">(bet_time)</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">拉取时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="pull_at" name="pull_at"
                               placeholder="yyyy-MM-dd HH:mm:ss"
                               value="{{old('pull_at',$playerBetFlow->pull_at)}}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">(pull_at)</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">创建时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="created_at" name="created_at"
                               placeholder="yyyy-MM-dd HH:mm:ss"
                               value="{{old('created_at',$playerBetFlow->created_at)}}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">(created_at)</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">修改时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="updated_at" name="updated_at"
                               placeholder="yyyy-MM-dd HH:mm:ss"
                               value="{{old('updated_at',$playerBetFlow->updated_at)}}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">(updated_at)</div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">是否有效</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="bet_flow_available" value="1" title="是"
                               @if($playerBetFlow->bet_flow_available==1) checked @endif>
                        <input type="radio" name="bet_flow_available" value="0" title="否"
                               @if($playerBetFlow->bet_flow_available==0) checked @endif>
                    </div>
                    <div class="layui-form-mid layui-word-aux">(bet_flow_available)</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">结算</label>
                    <div class="layui-input-inline">
                        <select name="status" lay-verify="" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <option value=1 @if((int)($playerBetFlow->status)===1) selected @endif>是</option>
                            <option value=0
                                    @if((int)($playerBetFlow->status)===0 || !isset($playerBetFlow->id)) selected @endif>否
                            </option>
                            <option value=-1 @if((int)($playerBetFlow->status)===-1) selected @endif>注销</option>
                        </select>

                    </div>
                    <div class="layui-form-mid layui-word-aux">(status)</div>
                </div>


            </div>


            <div class="layui-form-item">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>
    </div>
@endsection

@section('scripts')
    <script>
        layui.use('form', function () {
            var form = layui.form;

            form.on('checkbox(plats_id)', function (data) {
                if (data.elem.checked) {
                    document.getElementById(data.elem.getAttribute('data-id')).disabled = false;
                    document.getElementById(data.elem.getAttribute('data-id')).setAttribute('lay-verify', 'rate');
                } else {
                    document.getElementById(data.elem.getAttribute('data-id')).disabled = true;
                    document.getElementById(data.elem.getAttribute('data-id')).setAttribute('lay-verify', '');
                }

            });

            form.verify({
                rate: [
                    /^0\.\d{1,4}/
                    , '比率必须大于等于0保留一到四位小数，并且小于1，'
                ]
            });
        });

    </script>

    <script>
        layui.use(['upload','layer', 'form','laydate'], function () {
            var site=null,plat=null;
            var layer = layui.layer
                ,form = layui.form
                ,laydate = layui.laydate
                ,upload = layui.upload;
            //执行实例
            var uploadUrlImg1 = upload.render({
                elem: '#img1' // 绑定元素
                , url: '{{ route('upload.image') }}?folder=gameList&shearParam=200*200&object_id={{$group ?? 0}}' // 上传接口
                , field: 'upload_file'
                , done: function (res) {
                    if (res.success == true) {
                        $("#img1_url").val(res.file_uri);
                        $("#img1_file_path").attr("src", res.file_path);
                    }
                    //上传完毕回调
                    console.log(res);
                }
                , error: function () {
                    //请求异常回调
                    layer.alert('上传失败，请重试!', 2);
                }
            });

            var uploadUrlImg2 = upload.render({
                elem: '#img2' // 绑定元素
                , url: '{{ route('upload.image') }}?folder=gameList&shearParam=200*120&object_id={{$group ?? 0}}' // 上传接口
                , field: 'upload_file'
                , done: function (res) {
                    if (res.success == true) {
                        $("#img2_url").val(res.file_uri);
                        $("#img2_file_path").attr("src", res.file_path);
                    }
                    //上传完毕回调
                    console.log(res);
                }
                , error: function () {
                    //请求异常回调
                    layer.alert('上传失败，请重试!', 2);
                }
            });


            form.on('select(siteSelect)', function(data){
                site=data.value;
                var platsUrl="{{route('site.plats')}}";

                $.ajax({
                    type: 'POST',
                    url: platsUrl,
                    data: { username:site },
                    dataType:  'json',
                    success: function(data){
                        $("#plats").html("");
                        $.each(data, function(key, val) {
                            var option1 = $("<option>").val(val.main_game_plat_code).text(val.main_game_plat_name);
                            $("#plats").append(option1);
                            form.render('select');
                        });
                        $("#players").empty();
                        $("#plats").get(0).selectedIndex=0;

                    }
                });

            });


            form.on('select(platSelect)', function(data){
                plat=data.value;
                var playersUrl="{{route('site.players')}}";

                $.ajax({
                    type: 'POST',
                    url: playersUrl,
                    data: { username:site,plat:plat },
                    dataType:  'json',
                    success: function(data){
                        $("#players").html("");
                        $.each(data, function(key, val) {
                            var option1 = $("<option>").val(val.username).text(val.username);
                            $("#players").append(option1);
                            form.render('select');
                        });
                        $("#players").get(0).selectedIndex=0;
                    }
                });
            });


            //日期时间选择器
            laydate.render({
                elem: '#bet_time'
                , type: 'datetime'
            });

            laydate.render({
                elem: '#pull_at'
                , type: 'datetime'
            });
            laydate.render({
                elem: '#created_at'
                , type: 'datetime'
            });

            laydate.render({
                elem: '#updated_at'
                , type: 'datetime'
            });

        });
    </script>
@endsection